package com.sqfw.project.learnRecord.controller;

import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.project.learnRecord.domain.LearnRecordListen;
import com.sqfw.project.learnRecord.service.ILearnRecordListenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/learnRecord/listen")
public class LearnRecordListenController extends BaseController {

    @Autowired
    private ILearnRecordListenService learnRecordListenService;

    /**
     * 新增用户录音听取记录
     * @param learnRecordListen
     * @return
     */
    @PreAuthorize("@ss.hasPermi('api:learnRecord:listen')")
    @PostMapping
    public AjaxResult add(@RequestBody LearnRecordListen learnRecordListen){
        return toAjax(learnRecordListenService.insertLearnRecordListen(learnRecordListen));
    }

    /**
     * 查看录音统计按照所有人员
     * @return
     */
    @PreAuthorize("@ss.hasPermi('api:learnRecord:listen')")
    @GetMapping("/getInfoGroupByUser")
    public AjaxResult getGroupByUser(){
        return success(learnRecordListenService.getGroupByUser());
    }

    /**
     * 查看当前人员的录音统计
     * @param userId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('api:learnRecord:listen')")
    @GetMapping("/getByUserId/{userId}")
    public AjaxResult getByUserId(@PathVariable("userId") Long userId){
        return success(learnRecordListenService.getByUserId(userId));
    }
}
